<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-6-26
 * Time: 11:16
 */
namespace wxpay;
class SaoWxPay
{
    //$data 金额和订单号
    public function saoRequest($data)
    {
        //halt(intval($data['totalPrice']/1000));
        $appid = 'wxf4b7b2771a83d60b';
        $mch_id = '1530809431';//商户号
        $key = '63bdd8ce57da5f738f561b02945609ae';//商户key
        $notify_url = "wei.774945135.top";//回调地址
        //$wechatAppPay = new \wechatAppPay($appid, $mch_id, $notify_url, $key);
        $params['body'] = $data['describe'];                       //商品描述
        $params['out_trade_no'] = $data['orderNum'];    //自定义的订单号
        $params['total_fee'] = $data['totalPrice']*100;//intval($data['totalPrice']/10);                       //订单金额 只能为整数 单位为分
        $params['trade_type'] = 'NATIVE';                   //交易类型 JSAPI | NATIVE | APP | WAP
        $wxPay = new WxPay($appid,$mch_id,$notify_url,$key);
        $result = $wxPay->unifiedOrder($params);
        $img = $this->qrcode($result['code_url']);
        return $img;
//        return json_encode(['code'=>200,'data'=>$img]);

    }

    /**
     * 调用phpqrcode生成二维码
     * @param string $url 二维码解析的地址
     * @param int $level 二维码容错级别
     * @param int $size 需要生成的图片大小
     */
    public function qrcode($url)
    {
        include_once substr(getcwd(),0,-7).'/extend/phpcode/phpqrcode.php';
        $QRcode = new \QRcode();
        ob_start();
        $QRcode->png($url);
        $img = 'data:image/png;base64,' . base64_encode(ob_get_contents());
        ob_end_clean();
        return $img;
    }
}